import requests
import configparser
import json

def load_config():
    config = configparser.ConfigParser()
    config.read('config.ini')
    return config['server'].get('REMOTE_URL')

def send_http_request(url, data=None):
    try:
        if data:
            response = requests.post(url, json=data)
        else:
            response = requests.get(url)

        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"请求失败: {e}")
        return None

if __name__ == "__main__":
    remote_url = load_config()
    if not remote_url:
        print("配置文件中未找到REMOTE_URL")
    else:
        # 示例数据，可根据需要修改
        sample_data = {
            "username": "1",
            "text": '''channel,[0.3 4.0],[4.0 8.0],[8.0 12.0],[12.0 18.0],[18.0 30.0],[30.0 45.0]
Fp1,-0.133558050182945,0.553290601533361,-1.85765906791772,-0.104550673584133,-0.112176085364486,0.0923784266339265
Fp2,0.101918760471545,0.667163040289917,-1.91308436669607,-0.133467863897142,-0.197393469522798,0.209710213931858
Fz,-0.767887613440266,0.256228303915259,-1.73506012018574,-0.25015595099381,-0.240578226533741,0.0738154070870358
F3,-0.520196503341747,0.222834602452897,-1.85028962039425,0.0107440437887827,1.15836231891307,2.39357747437367
F4,0.0677141878573195,0.0136233892776723,-1.90402387855755,-0.130892883364953,0.27232612200978,1.78481526921585
F7,0.793704361588265,0.0943877967178168,-1.9592347147626,0.164058539692761,1.51413814158598,3.2032056121769
F8,-1.5689952091128,0.123176966543519,-2.05614690543962,0.223096031946563,0.991367556362037,3.22303171830986
FC1,-1.4143758401019,0.132575954786331,-1.6305827105945,-0.144073565985793,0.201251259115896,0.79091613217564
FC2,-1.25707050444125,-0.271926208898959,-1.70747351673548,-0.290884412354579,-0.0778985579235272,0.90398455823771
FC5,0.521978854449564,-0.184693834052577,-1.96850640015574,-0.0629557816946238,1.28164535755697,2.40960227868806
FC6,-1.57356672222243,-0.192768874302488,-2.01651196576695,-0.036818595368493,0.949300480477334,2.17299631304338
Cz,-2.88404885715384,-1.00465353400255,-1.38066921911214,-0.165046207979353,-0.169951928520534,0.135263179203552
C3,0.808816927800606,-0.194401970132262,-1.69694851358344,0.105231813344546,1.1065208770333,1.98808431751008
C4,-3.22095176383889,-0.260565347243614,-1.7058044865134,0.0330021157434928,1.07914815534804,2.43075793044388
T7,-0.811104860312842,-0.42439050677796,-1.97766989009314,0.214760553417761,2.183704961735,2.72208791137629
T8,-0.775554890696863,0.0487718553735642,-1.82690387071568,0.695858489000218,0.78410349411314,1.25532458451229
A1,-1.20278975401789e-05,-3.54649199607593e-06,1.70622692916567e-05,1.96691470621957e-05,-1.72286014032963e-06,-2.33879916855528e-06
A2,-1.20278975401789e-05,-3.54649199607593e-06,1.70622692916567e-05,1.96691470621957e-05,-1.72286014032963e-06,-2.33879916855528e-06
CP1,4.8243467702951,0.506601450617506,-1.0672767425154,0.152765001497922,0.598914833396469,0.695374120989218
CP2,-3.99188429723374,-1.67325644320095,-1.16405653460551,-0.420192588267993,-0.194960907328227,0.229566254758407
CP5,-2.63515267276724,-0.350725751317216,-1.55591381053006,-0.146068701956379,1.0514474728909,1.67441582601622
CP6,-1.56213241502769,-0.469045452498658,-1.03979891793075,-0.0516249090128182,-0.0375403716793503,0.852425194845315
Pz,-4.93191857264462,-0.445349108063519,-0.834393059999512,-0.167195677410671,-0.0981285271423555,-0.120214455564815
P3,-0.0725193052604567,-0.651623683081429,-0.840458353315668,-0.0938492184283639,0.227000394020452,0.206277575209013
P4,-2.22272205476906,-0.404862937434242,-0.667344214110354,-0.0713247576158864,0.00787015071936725,-0.354341372169872
P7,4.88640382604428,-0.193469226484757,-1.24855803676804,-0.363764876994427,0.0883685796458407,0.809243161737973
P8,-0.534009872696071,-0.577403239802121,-0.983771822023526,-0.311018327021983,-0.220401300166934,-0.453480066033611
PO3,0.679527855367066,-0.281580045482432,-0.712587404236524,0.220263034166165,0.205488937914509,0.183330064525904
PO4,2.36205569608481,-0.186021526587878,-0.749815205616603,-0.25433071418853,-0.203343150558762,-0.521922840980363
Oz,-0.337939862984207,0.115965900390084,-0.772019917181392,0.469221368981322,0.157854167737002,-0.0476090092155801
O1,0.429232780576051,0.0537233099510923,-0.858494298937119,0.559721789683495,0.336226176858923,0.0817224778022194
O2,-0.260931660493011,0.0181290171216197,-0.82490308600476169,-0.00747665677794669,-0.391971946525569,-0.65650624467893
'''
        }
        result = send_http_request(remote_url, sample_data)
        if result:
            print("请求成功，响应内容:")
            print(json.dumps(result, indent=2))
